import {
	defineStore
} from 'pinia';
import {
	ref,
	watch
} from 'vue';
export const useLoginStore = defineStore('login', () => {
	const loginState = ref(false);
	const userInfo = ref({
		avatar: "",
		birthday: "",
		nickName: "",
		nickTitle: "",
		phone: null,
		point: 0,
	});
	const memberInfo = ref({})
	const memberList = ref([])
	const showLogin = () => {
		loginState.value = true;
	}
	const hideLogin = () => {
		loginState.value = false;
	}
	const loginOut = () => {
		userInfo.value = {
			avatar: "",
			birthday: "",
			nickName: "",
			nickTitle: "",
			phone: null,
			point: 0,
		};
		uni.removeStorageSync("userInfo")
		uni.removeStorageSync("token");
		uni.reLaunch({
			url: "/pages/index/index"
		})
	}
	watch(userInfo, () => {
		uni.setStorageSync("userInfo", userInfo.value)
	})
	return {
		loginState,
		showLogin,
		hideLogin,
		userInfo,
		loginOut,
		memberInfo,
		memberList
	}
});